<template>
  <div class="workEnvContainer">
    <el-dialog
        title="工作环境配置"
        :visible.sync="dialogWorkEnv"
        width="420px"
        :before-close="closeALL">
            <div class="workEnvItem">
                <span>年度</span>
                <el-select v-model="allvalue.defaultFiscalYear" placeholder="请选择">
                    <el-option
                    v-for="(item) in allvalue.fiscalYears"
                    :key="item"
                    :label="item"
                    :value="String(item)"
                    >
                    </el-option>
                </el-select>
            </div>
            <div class="workEnvItem">
                <span>日期</span>
                <el-date-picker
                    v-model="value1"
                    type="date"
                    placeholder="选择日期">
                </el-date-picker>
            </div>
            <div class="workEnvItem">
                <span>组织</span>
                <el-select v-model="allvalue.defaultOrgId" placeholder="请选择">
                    <el-option
                    v-for="item in allvalue.useroffices"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    >
                    </el-option>
                </el-select>
            </div>
            <div class="workEnvItem">
                <span>账套</span>
                <el-select v-model="account" placeholder="请选择">
                    <el-option
                    v-for="item in accountList"
                    :key="item.id"
                    :label="item.label"
                    :value="item.id"
                    >
                    </el-option>
                </el-select>
            </div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="closeALL">取 消</el-button>
            <el-button type="primary" @click="workEnvSure">确 定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
import { createNamespacedHelpers } from 'vuex';
const { mapState, mapGetters, mapMutations, mapActions } = createNamespacedHelpers('homeModule');
import appUtil from '~/assets/utils/appUtil';

export default {
    name: 'WorkEnv',
    props: ['dialogWorkEnv'],
    data () {
        return {
            value1: '2020-08-13',
            organization: '', // 当前组织
            account: '', // 当前账套
            organizationList: [], // 组织列表
            accountList: [], // 账套列表
            defaultBizYear:'' // 当前年度
        };
    },
    inject: ['mainChannel'],
    computed: {
        ...mapState({
            allvalue:state => state.allvalue
        }),
        ...mapGetters([
        ])
    },
    created(){
        
    },
    methods:{
        ...mapMutations([
            
        ]),
        ...mapActions([
            'getAllvalueAsync',
            'saveWorkEnvAsync',
            'getMenuAsync'
        ]),
        // 关闭弹框
        closeALL () {
            // 子组件调用父组件的方法
            this.$parent.closeALL();
        },
        // 切换组织
        organizationChange(/*item*/){
            // console.log(item);
        },
        // 切换账套
        accountChange () {},
        // 工作环境设置提交
        async workEnvSure () {
            // 平台得清除
            this.$axios.get('/pf/crux/clearUserCloudContext');
            let params = {
                bizDate:this.value1,
                bizYear:this.allvalue.defaultBizYear,
                organizationId:this.allvalue.defaultOrgId
            };
            this.saveWorkEnvAsync(params).then(() => {
                // 重新获取菜单
                this.getMenuAsync();
                // 平台遗留的问题，这里传入的organizationId实际上是区划对象
                // this.mainChannel.state.colors = '#333';
                this.mainChannel.postMessage({
                    organizationId:appUtil.getSes('organizationId'),
                    bizYear:appUtil.setSes('bizYear')
                });
            });
            // 关闭弹框
            this.$parent.closeALL();
        }
    }
};
</script>

<style lang="scss" scoped>
.workEnvContainer{
    .workEnvItem{
        margin-top: 16px;
        margin-left: 46px;
        span{
            margin-right: 10px;
        }
    }
}
</style>
